import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_tv_widgets/widgets/formItem/entity/kq_form_entity.dart';
import 'package:kq_flutter_tv_widgets/widgets/textFiled/kq_textfiled.dart';

import '../../resources/kq_theme_colors.dart';
import '../../theme/kq_theme_manager.dart';

//输入多行样式
class KqEditMoreView extends StatefulWidget {
  const KqEditMoreView({
    super.key,
    required this.entity,
    this.height,
  });
  final KqFormEntity entity;
  //限制输入的高
  final double? height;
  @override
  State<KqEditMoreView> createState() => _KqEditMoreViewState();
}

class _KqEditMoreViewState extends State<KqEditMoreView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: KqThemeColors.bgDialog,
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.only(
                right: KqThemeManager.instance
                        .getConfig()
                        .formConfig
                        .paddingHorizontal ??
                    16.r,
                top: KqThemeManager.instance
                        .getConfig()
                        .formConfig
                        .paddingVertical ??
                    15.r),
            child: Row(
              children: <Widget>[
                ///是否必填
                Container(
                  alignment: Alignment.centerRight,
                  width: KqThemeManager.instance
                          .getConfig()
                          .formConfig
                          .paddingHorizontal ??
                      16.r,
                  padding: EdgeInsets.only(right: 2.r),
                  child: Text(
                    "*",
                    style: TextStyle(
                        fontSize: KqThemeManager.instance
                                .getConfig()
                                .formConfig
                                .mustInputFontSize ??
                            24.sp,
                        color: widget.entity.mustInput
                            ? KqThemeColors.textRed
                            : KqThemeColors.bgTransparent),
                  ),
                ),
                LimitedBox(
                  maxWidth: KqThemeManager.instance
                          .getConfig()
                          .formConfig
                          .titleMaxWidth ??
                      200.r,
                  child: Text(
                    widget.entity.title,
                    maxLines: widget.entity.multiline ? null : 1,
                    overflow:
                        widget.entity.multiline ? null : TextOverflow.ellipsis,
                    style: TextStyle(
                        fontSize: KqThemeManager.instance
                                .getConfig()
                                .formConfig
                                .titleFontSize ??
                            14.sp,
                        color: KqThemeColors.text26),
                  ),
                )
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.only(
                left: KqThemeManager.instance
                        .getConfig()
                        .formConfig
                        .paddingHorizontal ??
                    16.r,
                right: KqThemeManager.instance
                        .getConfig()
                        .formConfig
                        .paddingHorizontal ??
                    16.r,
                bottom: KqThemeManager.instance
                        .getConfig()
                        .formConfig
                        .paddingVertical ??
                    15.r,
                top: 4.r),
            alignment: Alignment.topLeft,
            height: widget.height ?? 126.r,
            child: KqTextFiled(
              multiline: true,
              maxLines: null,
              inputType: widget.entity.inputType,
              editable: widget.entity.editable,
              controller: widget.entity.controller,
              fontSize: KqThemeManager.instance
                  .getConfig()
                  .formConfig
                  .contentFontSize,
              enableClearButton: widget.entity.enableClearButton,
              textAlign: TextAlign.start,
              placeHolder: widget.entity.hint,
              maxCharCount: widget.entity.maxCharCount,
              inputFormatters: widget.entity.inputFormatters,
              onChanged: (text) {
                setState(() {
                  widget.entity.valueForShow = text;
                  widget.entity.valueForSubmit = text;
                });
              },
            ),
          )
        ],
      ),
    );
  }
}
